<?php
require ("../classDB.php");
$db = new db;

class customer extends db{
public function AddCustomer(){
		//Receive data
		$lname = $_POST['Ho'];
		$fname = $_POST['Ten'];
		
		$number = $_POST['sonha'];
		$street = $_POST['duong'];
		$idDistrict = $_POST['idDistrict'];
		$idWard = $_POST['idWard'];
		
		$email = $_POST['email'];
		$phone = $_POST['phone'];
		$career = $_POST['career'];
		$bday = $_POST['Ngay'];
		
		$baby_gender = $_POST['baby_gender'];
		$sex = $_POST['gioitinh'];
		$active = $_POST['active'];
				
			
		//Kiểm tra dữ liệu đã nhận
		settype($baby_gender,"int");	
		settype($sex,"int");	
		settype($active,"int");	
			
		//Check lname & fname
		$lname = trim(strip_tags($lname));
		$fname = trim(strip_tags($fname));
		$lname = mb_convert_case($lname , MB_CASE_TITLE , 'utf-8');
		$fname = mb_convert_case($fname , MB_CASE_TITLE , 'utf-8');
		
		//Check full address
		$number = trim(strip_tags($number));
		$street = trim(strip_tags($street));
		settype($idDistrict,"int");	
		settype($idWard,"int");	
		$street = mb_convert_case($street , MB_CASE_TITLE , 'utf-8');
		$number = mb_convert_case($number , MB_CASE_TITLE , 'utf-8');
		settype($idWard,"int");
		settype($idDistrict,"int");
		
		//Check email, phone, career, birthday
		$email = trim(strip_tags($email));
		settype($phone,"int");	
		$career = trim(strip_tags($career));
		$career = mb_convert_case($career , MB_CASE_TITLE , 'utf-8');
		$bday = trim(strip_tags($bday));
		
		//Check radio group

		if (get_magic_quotes_gpc()== false) {
			$lname = mysql_real_escape_string($lname);
			$fname = mysql_real_escape_string($fname);
			$career = mysql_real_escape_string($career);
			$number = mysql_real_escape_string($number);
			$street = mysql_real_escape_string($street);
			$bday = mysql_real_escape_string($bday);
		}
		
		//Check date
		$Ngay_arr = explode("/",$bday); // array(17,11,2010)
		if (count($Ngay_arr)==3) {
			$d = $Ngay_arr[0]; //17
			$m = $Ngay_arr[1]; //11
			$y = $Ngay_arr[2]; //2010
			if (checkdate($m,$d,$y)==false) $Ngay = date("Y-m-d");
			else $Ngay = $y."-".$m."-".$d;
		}
		else $Ngay=date("Y-m-d");
		//Insert into Customer		
		
		  
		$sql="INSERT INTO customer 
		  (lname, fname, career, email, phone, bday, number, street, idWard, idDistrict, baby_gender, sex, active)
		  VALUES ('$fname', '$lname', '$email', $phone, '$Ngay', '$number', $idWard, $idDistrict, $baby_gender, $sex, $active )";
		mysql_query($sql) or die(mysql_error());	
	}//end function AddCustomer
}
?>